﻿namespace Rialternative.Repositories
{
    using System;
    using System.Linq;

    /// <summary>
    /// Defines a contract for a repository which implement C.R.U.D methods.
    /// </summary>
    public interface IRepository : IDisposable
    {
        /// <summary>
        /// Gets the query.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <returns>A queryable object relative to the entity.</returns>
        IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class;

        /// <summary>
        /// Inserts the specified entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity.</param>
        void Insert<TEntity>(TEntity entity) where TEntity : class;

        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="original">The original version of the entity.</param>
        void Update<TEntity>(TEntity entity, TEntity original) where TEntity : class;

        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity.</param>
        void Delete<TEntity>(TEntity entity) where TEntity : class;

        /// <summary>
        /// Persists changes.
        /// </summary>
        void Persist();
    }
}
